<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ page isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html>
<head>
<link href="<s:url value="/resources"/>/css/style_new.css"
	rel="stylesheet" type="text/css" />
<link href="<s:url value="/resources"/>/css/main_new.css"
	rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" media="screen"
	href="<s:url value="/resources"/>/css/cupertino/jquery-ui.min.css" />
<link rel="stylesheet" type="text/css" media="screen"
	href="<s:url value="/resources"/>/css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen"
	href="<s:url value="/resources"/>/css/ui.multiselect.css" />
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script>
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/i18n/grid.locale-cn.js"></script>
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/jquery.jqGrid.min.js"></script>
<script type="text/javascript"
	src="<s:url value="/resources"/>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>

<style>
html,body {
	margin: 0;
	padding: 0;
	font-size: 85%;
}
</style>
</head>

<script type="text/javascript"> 
   var qieye = 0;

  $(function(){ 
    $("#xinz").button(); 
    $("#chax").button();
    $("#shanc").button(); 
     $("#reset").button();
    loadTab(0);
    jQuery("#myTab0").jqGrid('hideCol',["jiesrname"]);
    $( "#datepicker" ).datepicker($.datepicker.regional[ "zh-CN" ]);
    $( "#datepicker1" ).datepicker($.datepicker.regional[ "zh-CN" ]);
     jQuery("#myTab"+qieye).jqGrid('hideCol',["url"]);
     jQuery("#myTab"+qieye).jqGrid('hideCol',["Caoz"]);
    $( "#tabs" ).tabs({
		    select: function(event, ui) {
		    var i =ui.index;	    
		    if(i==''){
		    i="0";
		    }
		    qieye = i;
		    loadTab(i);
		    $("#myTab"+qieye).jqGrid('setGridParam',{url:'findMsglist?index='+i,mtype:'post',page:1}).trigger("reloadGrid");
		   // alert("aa");
		   
		          
		    if(i=='0'){
		    jQuery("#myTab0").jqGrid('hideCol',["jiesrname"]);
		    //jQuery("#myTab0").jqGrid('showCol',["fasrname"]);
		    
		    }
		    if(i=='1'){
		   jQuery("#myTab1").jqGrid('hideCol',["fasrname"]);
		   jQuery("#myTab1").jqGrid('hideCol',["Caoz"]);
		   
		    }
            //return false;
  		  }
		
	});
    
 });
  
  
  
  
  
   
  function loadTab(i){    
  
      $("#myTab"+i).jqGrid({      
    url:'findMsglist?index=' + i,   
    datatype: 'json',
    mtype: 'post',         
   	colNames:['查看','操作','发件人','收件人', '消息内容', '消息时间','消息状态','url'],
   	colModel:[   		
   	    {name:'Modify',index:'id',width:80,align:"center",sortable:false},
   	    {name:'Caoz',index:'id',width:80,align:"center",sortable:false},
   		{name:'fasrname',index:'fasrname', width:100},
   		{name:'jiesrname',index:'jiesrname', width:100},
   		{name:'xiaoxnr',index:'xiaoxnr', width:300 ,formatter:function(cellvalue, options, rowObject){
   		if(cellvalue.length>10){ return cellvalue.substr(0,25)+"...";}else{return cellvalue;}
   		
}
   		},
   		{name:'fssj',index:'fssj', width:120 },
   		{name:'xxztname',index:'xxztname', width:120 },
   		{name:'url',index:'url', width:120 },

   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'msgid'
         },    	
   	rowNum:10,
   	rowList:[10,20,30],     	
   	pager: '#pager'+i,
   	rownumbers: true,   	 
    viewrecords: true,
    multiselect: true,
    loadError: function (r, st, error) {
    $("#message"+i).html("status is " + r.status+error+st);
},
	//caption: "消息列表",
	gridComplete:function(){ //在此事件中循环为每一行添加修改和删除链接 
var ids=jQuery("#myTab"+i).jqGrid('getDataIDs'); 
for(var j=0; j<ids.length; j++){ 
var id=ids[j]; 
modify ="<a href='#' style='color:#f60' onclick='Modify("+ id +")'>查看</a>"; //这里的onclick就是调用了上面的javascript函数 Modify(id) 
caoz="<a href='#' style='color:#f60' onclick='Caoz("+id+")'>处理</a>";
jQuery("#myTab"+i).jqGrid('setRowData',ids[j], { Modify: modify,Caoz :caoz}); 
} 
} 

  });
  
   $("#myTab"+i).jqGrid('setGridHeight','240px');
  }
  
  
  function Caoz(id) { 
  
  var model = jQuery("#myTab"+qieye).jqGrid('getRowData', id); 
  //alert(model.url);
  openwindow(model.url);
  }
  
  //查看
  function Modify(id) { //单击修改链接的操作 
//var model = jQuery("#myTab"+qieye).jqGrid('getRowData', id); 

//alert(id);

var url= "findMsgById?index="+qieye+"&xiaoxid="+id;
	$.post(url, function(data){
	 var json = eval('(' + data + ')');
	 // alert("Data Loaded: " + json.xiaoxnr);
	 $("#txtxiaoxnr").val(json.xiaoxnr);
	  $("#modifyform").dialog({ 
		height:400, 
		width:600, 
		resizable:false, 
		modal:true, //这里就是控制弹出为模态 
		buttons:{  
		"关闭":function()
		{
		
		//location.reload();
		 $("#myTab"+qieye).jqGrid('setGridParam',{url:'findMsglist?index='+qieye,mtype:'post',page:1}).trigger("reloadGrid");     
		$(this).dialog("close");} 
		} 
		});                 
	  });
} 



    

// 查询
function search(){   
  var formdata = $("#form1").serialize();  
  $("#myTab"+qieye).jqGrid('setGridParam',{url:'findMsglist?'+formdata+'&index='+qieye,mtype:'post',page:1}).trigger("reloadGrid"); 
}

//重置
			function resetSearch(){
			   $('#list_search  input[type=text]').val('');
			   $('#list_search select').val('-1');
			 }
function removeRow() {
	var s = $("#myTab"+qieye).jqGrid('getGridParam','selarrrow');
	var url = "<s:url value="/"/>/jysxx/removeReceiveMsg?msgid="+s;
	
	if (s=="") {alert("请选择需要删除的消息！"); return；}
	$( "#dialog-confirm" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
				
					$.post(url, function(data) {
                    //alert(data); 
                    //location.reload();   
                     $("#myTab"+qieye).jqGrid('setGridParam',{url:'findMsglist?index='+qieye,mtype:'post',page:1}).trigger("reloadGrid");                   
                   });
                   $( this ).dialog( "close" ); 
                    
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});

}
</script>
<body>
	<div class="container">
		<div class="containerbox">

			<div class="btn-bar">
				<a href="<s:url value="/"/>/views/cxtj/xtxx/xtxx_add.jsp" class="btn"
					><img
					src="<s:url value="/resources"/>/img/ico_23.gif" /><span>新增</span>
				</a> <a href="#" class="btn" onclick="removeRow();"><img
					src="<s:url value="/resources"/>/img/ico_25.gif" /> <span>删除</span>
				</a>

			</div>

			<!--  	<form id="form1" method="post">
					<table width="90%" border="0" cellspacing="0" cellpadding="0" class="search-table">
						<tr>
							<td class="pr10 search-table-70">发件人:</td>
							<td><input type="text"  name="aa"
								class="form-textbox" />
							</td>
							<td class="pr10 search-table-70">消息时间:</td>
							<td colspan="2" class="pr10 search-table-200"><input
								id="datepicker" type="text"  name="cc"
								class="form-textbox" /> -- <input id="datepicker1" type="text"
								 name="dd" class="form-textbox" />
							</td>
							<td class="pr10 search-table-70">消息状态:</td>
							<td><select name="bb" style="width:180px"
								class="form-textbox">
									<option value="-1" selected>==请选择==</option>
									<c:forEach var="xxzt" items="${xxzt}">
										<option value="${xxzt.diccode}">${xxzt.dicname}</option>
									</c:forEach>
							</select></td>

						</tr>

					</table>

<table cellpadding="0" cellspacing="0" border="0">
						<tr>

							<td colspan="2" align="right"><input id="chax" type="button"
								value="查询" onclick="search();"
								class="form-button-query form-button" /><input id="reset"
								type="button" class="form-button-reset form-button" value="重置"
								onclick="resetSearch();" /></td>

						</tr>
					</table>
					
				</form>
			-->

			<div class="search mt10" id="list_search">
				<form id="form1" method="post">
					<table width="90%" border="0" cellspacing="0" cellpadding="0"
						class="search-table">
						<tr>
							<td align="right" class="pr10 search-table-70"><table
									border="0" cellspacing="0" cellpadding="0"
									class="search-table-300">
									<tr>
										<td align="right" class="pr10 search-table-70">发件人</td>
										<td align="left"><input name="aa" type="text"
											class="form-textbox" style="width: 200px;" /></td>
									</tr>
								</table></td>
							<td align="left" valign="middle"><table border="0"
									cellspacing="0" cellpadding="0" class="search-table-300">
									<tr>
										<td align="right" class="pr10 search-table-70">消息时间:</td>
										<td align="left"><input name="cc" type="text"
											class="form-textbox" style="width: 93px;" id="datepicker" />--
											<input name="dd" type="text" class="form-textbox"
											style="width: 93px;" id="datepicker1" /></td>
									</tr>
								</table></td>
							<td align="left" valign="middle"><table border="0"
									cellspacing="0" cellpadding="0" class="search-table-300">
									<tr>
										<td align="right" class="pr10 search-table-70">消息状态:</td>
										<td align="left"><select name="bb" style="width:180px"
											class="form-textbox">
												<option value="-1" selected>==请选择==</option>
												<c:forEach var="xxzt" items="${xxzt}">
													<option value="${xxzt.diccode}">${xxzt.dicname}</option>
												</c:forEach>
										</select></td>
									</tr>
								</table></td>
						</tr>
						<tr>
							<td align="left" valign="middle" colspan="3"><table
									border="0" cellspacing="0" cellpadding="0">
									<tr>
										<td align="right" class="pr10 search-table-70">&nbsp;</td>
										<td align="left"><input name="" type="button"
											class="form-button-query form-button" value="查询"
											onclick="search();" /> <input name="" type="button"
											class="form-button-reset form-button" value="重置"
											onclick="resetSearch();" /></td>
									</tr>
								</table></td>
						</tr>
					</table>
				</form>
			</div>

			<div id="tabs">
				<ul>
					<li><a href="#tabs-0">收件箱</a></li>
					<li><a href="#tabs-1">发件箱</a></li>
				</ul>
				<div id="tabs-0">
					<table id="myTab0" class="infolist mt10" " cellpadding="0"
						cellspacing="0"></table>
					<div id="pager0" class="scroll"></div>
					<div id="message0" class="scroll"></div>
				</div>
				<div id="tabs-1">
					<table id="myTab1" class="infolist mt10" " cellpadding="0"
						cellspacing="0"></table>
					<div id="pager1" class="scroll"></div>
					<div id="message1" class="scroll"></div>
				</div>
			</div>
			<div id="dialog-confirm" title="是否确认删除？"></div>

			<div id="modifyform" title="查看内容" style="display:none;">
				<table cellpadding="0" cellspacing="0" border="0"
					class="content_gridview">
					<tr>
						<td><textarea cols="90" rows="18" class="textarea"
								style="width:100%; background-color:#EEEEEE ; border-color:#b7dde8"
								id="txtxiaoxnr"></textarea></td>
					</tr>


				</table>
			</div>
		</div>
	</div>
</body>
</html>
